package com.one.consumer.main.ui.fragment;

import android.os.Build;
import android.os.Handler;
import android.support.annotation.RequiresApi;
import android.widget.ImageView;
import android.widget.RelativeLayout;
import android.widget.TextView;

import com.one.common.config.CMemoryData;
import com.one.common.config.MyContact;
import com.one.common.config.RouterPath;
import com.one.common.manager.RouterManager;
import com.one.common.manager.imageloader.ILoader;
import com.one.common.manager.imageloader.LoaderManager;
import com.one.common.model.bean.UserInfoBean;
import com.one.common.model.http.RxHelper;
import com.one.common.utils.StringUtils;
import com.one.common.utils.SystemUtils;
import com.one.common.view.base.BaseFragment;
import com.one.common.view.widget.HorizontalMenuItem;
import com.one.consumer.R;
import com.one.consumer.main.ui.MainActivity;
import com.one.common.common.order.extra.ReserveExtra;

import butterknife.BindView;
import butterknife.OnClick;
import butterknife.Unbinder;

/**
 * author ：zhulunjun
 * email  ：zhulunjun@qq.com
 * date   ：2018/10/21 上午10:46
 * description ：我的页面
 **/
public class MyFragment extends BaseFragment {
    @BindView(R.id.iv_avatar)
    ImageView ivAvatar;
    @BindView(R.id.tv_name)
    TextView tvName;
    @BindView(R.id.tv_phone)
    TextView tvPhone;
    @BindView(R.id.hmi_1)
    HorizontalMenuItem hmi1;
    @BindView(R.id.hmi_2)
    HorizontalMenuItem hmi2;
    @BindView(R.id.hmi_3)
    HorizontalMenuItem hmi3;
    @BindView(R.id.hmi_4)
    HorizontalMenuItem hmi4;
    @BindView(R.id.hmi_5)
    HorizontalMenuItem hmi5;
    @BindView(R.id.hmi_6)
    HorizontalMenuItem hmi6;
    @BindView(R.id.hmi_7)
    HorizontalMenuItem hmi7;
    @BindView(R.id.hmi_8)
    HorizontalMenuItem hmi8;
    @BindView(R.id.rl_user)
    RelativeLayout rlUser;
    Unbinder unbinder;
    private UserInfoBean userInfoBean;

    @Override
    protected void initPresenter() {

    }

    @Override
    public int getLayoutResId() {
        return R.layout.frament_my;
    }


    @Override
    public void onResume() {
        super.onResume();
        new Handler().postDelayed(() -> setUserInfo(), 1000);
    }

    /**
     * 设置用户信息
     */
    private void setUserInfo() {
        userInfoBean = CMemoryData.getUserInfo();
        if (userInfoBean != null && ivAvatar != null) {
            if (StringUtils.isNotBlank(userInfoBean.getMember_img())) {
                ILoader.Options options = new ILoader.Options(R.mipmap.ic_avatar_default, R.mipmap.ic_avatar_default, true);
                LoaderManager.getLoader().loadNet(ivAvatar, userInfoBean.getMember_img(), options);
            }
            tvName.setText(userInfoBean.getMember_nick_name());
            tvPhone.setText(userInfoBean.getMember_account());

        }
    }

    /**
     * 设置用户信息
     */
    @OnClick(R.id.rl_user)
    public void setUser() {
        RouterManager.getInstance().go(RouterPath.SET_USER);
    }

    /**
     * 维修订单
     */
    @OnClick(R.id.hmi_1)
    public void deOrder() {
        MainActivity activity = (MainActivity) getActivity();
        activity.changePage(1);
    }

    /**
     * 装修订单
     */
    @OnClick(R.id.hmi_2)
    public void dyOrder() {
        RouterManager.getInstance().go(RouterPath.DE_CU_ORDER, new ReserveExtra(ReserveExtra.STYLE_DE));
    }

    /**
     * 装配订单
     */
    @OnClick(R.id.hmi_3)
    public void cuOrder() {
        RouterManager.getInstance().go(RouterPath.DE_CU_ORDER, new ReserveExtra(ReserveExtra.STYLE_CU));
    }

    /**
     * 开票记录
     */
    @OnClick(R.id.hmi_4)
    public void billingOrder() {
        RouterManager.getInstance().go(RouterPath.INVOICE_LIST);
    }

    /**
     * 预约中心
     */
    @OnClick(R.id.hmi_5)
    public void reservOrder() {
        RouterManager.getInstance().go(RouterPath.RESERVE_CENTER);
    }

    /**
     * 联系我们
     */
    @RequiresApi(api = Build.VERSION_CODES.HONEYCOMB)
    @OnClick(R.id.hmi_6)
    public void kefu() {
        SystemUtils.call(getActivity(), MyContact.PHONE_KEFU);
    }

    /**
     * 设置
     */
    @OnClick(R.id.hmi_7)
    public void setting() {
        RouterManager.getInstance().go(RouterPath.SETTING);
    }

    /**
     * 设置
     */
    @OnClick(R.id.hmi_8)
    public void youhuijuan() {
        RouterManager.getInstance().go(RouterPath.youhuijuan_list);
    }


}
